package com.fpt.edu.jornee.utils;

import java.util.ArrayList;
import java.util.HashMap;

import com.fpt.edu.jornee.MainActivity;
import com.fpt.edu.jornee.R;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.webkit.WebView.FindListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MenuNavigationListAdapter extends BaseAdapter {
	private static final int TYPE_ITEM1 = 0;
	private static final int TYPE_ITEM2 = 1;
	private Activity activity;
	private ArrayList<HashMap<String, String>> data;

	private static LayoutInflater inflater = null;
	public ImageLoader imageLoader;

	public MenuNavigationListAdapter(Activity a,
			ArrayList<HashMap<String, String>> d) {
		activity = a;
		data = d;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		imageLoader = new ImageLoader(activity.getApplicationContext());

	}

	public int getCount() {
		return data.size();
	}

	public Object getItem(int position) {
		return data.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	int type;

	@Override
	public int getItemViewType(int position) {

		if (position == 0) {
			type = TYPE_ITEM1;
		} else if (position != 0) {
			type = TYPE_ITEM2;
		}

		return type;
	}

	@Override
	public int getViewTypeCount() {
		return 2;
	}
	public static class ViewHolder {
        public TextView textView;
    }
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;

		int type = getItemViewType(position);

		if (convertView == null) {
			if (type == TYPE_ITEM1) {
				System.out.println("bbbbb MenuNavigationListAdapter.getView()");
				vi = inflater.inflate(
						R.drawable.menu_navigation_list_row_user_avatar, null);
				
				ImageView imageView = (ImageView) vi.findViewById(R.id.userAvatar);
				
				TextView textView = (TextView) vi.findViewById(R.id.login);
				HashMap<String, String> functionNames = new HashMap<String, String>();
				functionNames = data.get(position);

//				TextView = (TextView) vi
//						.findViewById(R.id.functionName);
//				HashMap<String, String> functionNames = new HashMap<String, String>();
//
//
//				Log.d("LazyAdapter	", "LazyAdapter hereeeeeeeeee");
//
//				holder.textView.setText(functionNames
//						.get(MainActivity.FUNCTION_NAME));

			}
			if (type == TYPE_ITEM2) {
				System.out.println("bbbbb MenuNavigationListAdapter.getView()");
				vi = inflater.inflate(
						R.drawable.menu_navigation_list_row_function, null);
				TextView functionName = (TextView) vi
						.findViewById(R.id.functionName);
				HashMap<String, String> functionNames = new HashMap<String, String>();

				functionNames = data.get(position);

				Log.d("LazyAdapter	", "LazyAdapter hereeeeeeeeee");

				functionName.setText(functionNames
						.get(MainActivity.FUNCTION_NAME));

			}
		}
		return vi;

	}

}
